#!/bin/bash

clear

JNI=/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/include

DNILIB=../../lib
DNIBIN=../../bin
DNICP=${DNILIB}/asm-debug-all-4.0.jar:${DNILIB}/junit-4.10.jar:${DNIBIN}
DNICPW="${DNILIB}/asm-debug-all-4.0.jar;${DNILIB}/junit-4.10.jar;${DNIBIN}"
mkdir -p  ../../lib/linux-x86
mkdir -p  ../../lib/linux-x86_64
mkdir -p  ../../lib/windows-x86
mkdir -p  ../../lib/windows-x86_64

MOOARGS="-Wall -fPIC -shared -Wl,-soname,libdni.so -I/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/include -I/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/include/linux -fPIC -O3 -lm"
TESTARGS="-Wall -fPIC -shared -Wl,-soname,libdnitest.so -I/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/include -I/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/include/linux -fPIC -O3 -lm"

DNILIB=../../lib
TESTSRC=../../test/native


################################################################################
echo Linux x86...
gcc -m32 $MOOARGS -o ${DNILIB}/linux-x86/libdni.so   *.c linux/*.c linux/x86/*.[cs]
gcc -m32 $TESTARGS -o ${DNILIB}/linux-x86/libdnitest.so  ${TESTSRC}/*.c

/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.1/jre/bin/java -Djava.library.path=${DNILIB}/linux-x86/ -cp ${DNICP} com.googlecode.dni.test.AllTests &>tests-linux-x86.log



################################################################################
echo Linux x86_64...
gcc -m64 $MOOARGS -o ../../lib/linux-x86_64/libdni.so *.c linux/*.c linux/x86_64/*.[cs]
gcc -m64 $TESTARGS -o ../../lib/linux-x86_64/libdnitest.so ${TESTSRC}/*.c

java -Djava.library.path=${DNILIB}/linux-x86_64/ -cp ${DNICP} com.googlecode.dni.test.AllTests &>tests-linux-x86_64.log



################################################################################
echo Windows x86...

rm -fr *.obj *.lib *.exp

cl /nologo /O2 /c *.c windows\\*.c
ml /nologo /c windows\\x86\\X86_CDecl_Windows.asm
ml /nologo /c windows\\x86\\X86_StdCall_Windows.asm
vc_link /nologo /DLL /out:..\\..\\lib\\windows-x86\\dni.dll *.obj /def:windows\\x86\\X86_Windows.def
rm -fr *.obj *.lib *.exp

cl /nologo /O2 /c ..\\..\\test\\native\\*.c
vc_link /nologo /DLL /out:..\\..\\lib\\windows-x86\\dnitest.dll *.obj
rm -fr *.obj *.lib *.exp

java_w32 -Djava.library.path=${DNILIB}/windows-x86/ -cp ${DNICPW} com.googlecode.dni.test.AllTests &>tests-windows-x86.log

# TODO Test lib!

################################################################################
echo Windows x86_64...

cl64 /nologo /O2 /c *.c windows\\*.c
ml64 /nologo /c windows/x86_64/*.asm
vc_link64 /nologo /DLL /out:..\\..\\lib\\windows-x86_64\\dni.dll *.obj /def:windows\\x86_64\\X86_64_Windows.def
rm -fr *.obj *.lib *.exp

cl64 /nologo /O2 /c ..\\..\\test\\native\\*.c
vc_link64 /nologo /DLL /out:..\\..\\lib\\windows-x86_64\\dnitest.dll *.obj
rm -fr *.obj *.lib *.exp

java_w64 -Djava.library.path=${DNILIB}/windows-x86_64/ -cp ${DNICPW} com.googlecode.dni.test.AllTests &>tests-windows-x86_64.log

# TODO Test lib!
